﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Site
{
    public partial class Message : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Type"] == "Register")
            {
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();

                Response.ContentType = "text/plain";

                Response.Write("OK");
                Response.End();
                return;
            }
            else if (Request.QueryString["Type"] == "Check")
            {
                SqlDataSource1.SelectCommand = "SELECT * FROM Messages WHERE PID='" + Request.QueryString["PID"] + "'";
                DataView View = (DataView)SqlDataSource1.Select(new DataSourceSelectArguments());

                string Out = "";

                foreach (DataRowView DRV in View)
                {
                    Out += DRV["Body"] + "|" + DRV["From"] + "$";
                }

                SqlDataSource1.DeleteCommand = "DELETE FROM Messages WHERE PID='" + Request.QueryString["PID"] + "'";
                SqlDataSource1.Delete();


                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();

                Response.ContentType = "text/plain";

                Response.Write(Out);
                Response.End();
                return;
            }
        }
    }
}